package com.example.springjpa.repository;

import com.example.springjpa.model.Student;
import com.example.springjpa.vo.StudentResult;
import com.example.springjpa.vo.StudentVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface StudentRepository extends JpaRepository<Student, Long> {

    @Query(value = "select s.name, s.age, c.name as clazzName from t_student s left join t_clazz c on s.clazz_id = c.id where c.id = ?1", nativeQuery = true)
    List<Map<String, Object>> queryMap(Long clazzId);

    @Query("select new com.example.springjpa.vo.StudentVo(s.id, s.name, c.name) from Student s left join Clazz c with s.clazzId = c.id where c.id = ?1")
    List<StudentVo> queryVo(Long clazzId);

    @Query(value = "select s.id, s.name, c.name as clazzName from t_student s left join t_clazz c on s.clazz_id = c.id where c.id = ?1", nativeQuery = true)
    List<StudentResult> queryInterface(Long clazzId);
}
